package mapEditor.interactor;

//import debug.*;
	
import mapEditor.map.MapCanvas;
import mapEditor.obj.PathObject;
import mapEditor.utils.MapLocation;

import java.awt.Graphics2D;


// ********************************************************************
// *** CLASS: PolygonMouseAdapter
// ********************************************************************
public class DrawPolygonInteractor extends MapInteractorAdapter
{ public String getMouseModeMnemonic() { return("DrawPolygon"); }
  private PathObject polygon; // !null when drawing


  // ******************************************************************
  // *** CONSTRUCTOR: PolygonMouseAdapter
  // ******************************************************************
  public DrawPolygonInteractor(MapCanvas mapCanvas)
  { super(mapCanvas,DRAW_POLYGON);  
  }
  // ******************************************************************
  // *** METHOD: paintMouseEffect
  // ******************************************************************
  public void paintMouseEffect(Graphics2D g)
  {	if(polygon!=null) polygon.paint((Graphics2D)g);
  }

  // ******************************************************************
  // *** METHOD: mouseDragged
  // ******************************************************************
  // Invoked when a mouse button is pressed and then dragged.
  protected void mouseDragged() { }


  // ******************************************************************
  // *** METHOD: mouseMoved
  // ******************************************************************
  // Invoked when the mouse has been moved (with no buttons down).
  protected void mouseMoved() {}

  // ******************************************************************
  // *** METHOD: mousePressed
  // ******************************************************************
  // Invoked when a mouse button has been pressed.
  protected void mouseLeftPressed(MapLocation p)
  { 
  }
  protected void mouseRightPressed(MapLocation p)
  {
  }

  // ******************************************************************
  // *** METHOD: mouseReleased
  // ******************************************************************
  // Invoked when a mouse button has been released.
  protected void mouseLeftReleased(MapLocation p)
  { if(polygon==null) polygon=new PathObject(mapCanvas.getDOMTree(),p);
	else polygon.add(p);
	mapCanvas.repaint();
  }
  protected void mouseRightReleased(MapLocation p)
  { if(polygon!=null)
	{ if(polygon.numberOfPoints()>2) mapCanvas.drawObjectDone(polygon,"POLYGON");
	  polygon=null;
	}
  }

}